package lily.phs.object;

import lily.phs.database.Constants;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;


public class NonimmuneVaccineHistory implements Constants{
	
	private Context mContext;
	
	private int novh_profileid=-1;
	private int novh_testid=-1;
	private int novh_id=0;
	private String novh_name="";
	private String novh_date="";
	private String novh_hospital="";
	
	public NonimmuneVaccineHistory(Context context){
		this.mContext = context;
	}

	public int getNovh_profileid() {
		return novh_profileid;
	}

	public void setNovh_profileid(int novh_profileid) {
		this.novh_profileid = novh_profileid;
	}

	public int getNovh_testid() {
		return novh_testid;
	}

	public void setNovh_testid(int novh_testid) {
		this.novh_testid = novh_testid;
	}

	public int getNovh_id() {
		return novh_id;
	}

	public void setNovh_id(int novh_id) {
		this.novh_id = novh_id;
	}

	public String getNovh_name() {
		return novh_name;
	}

	public void setNovh_name(String novh_name) {
		this.novh_name = novh_name;
	}

	public String getNovh_date() {
		return novh_date;
	}

	public void setNovh_date(String novh_date) {
		this.novh_date = novh_date;
	}

	public String getNovh_hospital() {
		return novh_hospital;
	}

	public void setNovh_hospital(String novh_hospital) {
		this.novh_hospital = novh_hospital;
	}

	public void insertNonimmuneVaccineHistory(){
//		int result = -1;
		ContentValues value = new ContentValues();
		value.put(NOVH_COLUMN1, this.getNovh_profileid());
		value.put(NOVH_COLUMN5, this.getNovh_testid());
		value.put(NOVH_COLUMN6, this.getNovh_id());
		value.put(NOVH_COLUMN2, this.getNovh_name());
		value.put(NOVH_COLUMN3, this.getNovh_date());
		value.put(NOVH_COLUMN4, this.getNovh_hospital());
		
		mContext.getContentResolver().insert(CONTENT_URI_TB9, value);
//		return result;
		
	}
	
	/**
	 * 检出疫苗注射信息，并实例化对象
	 * @param profileId 档案编号
	 * @param testId 体检表编号
	 * @param _Id 疫苗注射
	 */
	public void selectNonimmuneVaccineHistory(int profileId,int testId,int _Id){
		String where = NOVH_COLUMN6 + "=" + _Id + " and "+NOVH_COLUMN1 + "=" + profileId + " and "+NOVH_COLUMN5 + "=" + testId + "";
		Cursor cursor = mContext.getContentResolver().query(CONTENT_URI_TB9, null, where, null, null);
		if(cursor.moveToNext()){
		this.novh_profileid = cursor.getInt(cursor.getColumnIndex(NOVH_COLUMN1));
		this.novh_testid = cursor.getInt(cursor.getColumnIndex(NOVH_COLUMN5));
		this.novh_id = cursor.getInt(cursor.getColumnIndex(NOVH_COLUMN6));
		this.novh_name = cursor.getString(cursor.getColumnIndex(NOVH_COLUMN2));
		this.novh_date = cursor.getString(cursor.getColumnIndex(NOVH_COLUMN3));
		this.novh_hospital = cursor.getString(cursor.getColumnIndex(NOVH_COLUMN4));
		}
		cursor.close();
	}
	
	/**
	 * 更新疫苗注射信息，并实例化对象
	 * @param profileId 档案编号
	 * @param testId 体检表编号
	 * @param _Id 疫苗注射
	 */
	public void updateNonimmuneVaccineHistory(int profileId,int testId,int _Id){
		ContentValues value = new ContentValues();
		value.put(NOVH_COLUMN1, this.getNovh_profileid());
		value.put(NOVH_COLUMN5, this.getNovh_testid());
		value.put(NOVH_COLUMN6, this.getNovh_id());
		value.put(NOVH_COLUMN2, this.getNovh_name());
		value.put(NOVH_COLUMN3, this.getNovh_date());
		value.put(NOVH_COLUMN4, this.getNovh_hospital());
		
		String where = NOVH_COLUMN6 + "=" + _Id + " and "+NOVH_COLUMN1 + "=" + profileId + " and "+NOVH_COLUMN5 + "=" + testId + "";
		mContext.getContentResolver().update(CONTENT_URI_TB9, value, where, null);
		
	}
	
	/**
	 * 删除患者的某次疫苗注射信息，并实例化对象
	 * @param profileId 档案编号
	 * @param testId 体检表编号
	 * @param _Id 疫苗注射
	 */
	public void delectNonimmuneVaccineHistory(int profileId,int testId,int _Id){
		String where = NOVH_COLUMN6 + "=" + _Id + " and "+NOVH_COLUMN1 + "=" + profileId + " and "+NOVH_COLUMN5 + "=" + testId + "";
		mContext.getContentResolver().delete(CONTENT_URI_TB9, where, null);
		
	}
	
	/**
	 * 删除患者的全部疫苗注册信息
	 * @param profileId 档案编号
	 */
	public void delectNonimmuneVaccineHistory(int profileId){
		String where = NOVH_COLUMN1 + "=" + profileId + "";
		mContext.getContentResolver().delete(CONTENT_URI_TB9, where, null);
		
	}
}
